# -*- coding: UTF-8 -*-
import cv2
import numpy as np
import proxy_and_image as pro

# pro.get_image_from_camera(camera_id, camera_proxy, videoClient) cv2.4版本使用模板匹配法完成视觉识别


def recognize(mat):

    template = cv2.imread("jiantou16.jpg", cv2.IMREAD_GRAYSCALE)
    w, h = template.shape[::-1]
    gray_frame = cv2.cvtColor(mat, cv2.COLOR_BGR2GRAY)
    res = cv2.matchTemplate(gray_frame, template, cv2.TM_CCOEFF_NORMED)
    loc = np.where(res >= 0.55)
    for pt in zip(*loc[::-1]):
        cv2.rectangle(mat, pt, (pt[0] + w, pt[1] + h), (0, 255, 0), 3)
        # global a
        if pt[1] + h:
            print ("SBDFX")
            a = True
            print("a", a)
            return a
        else:
            a = False
            return a

    # self._Image = cv2.cvtColor(mat, cv2.COLOR_BGR2RGB)  # 将BGR转为RGB
    cv2.imshow("Frame", mat)